package org.space.ai.feign.fallback;

import com.galaxy.common.mybatis.core.page.TableDataInfo;
import org.space.ai.domain.ProductBo;
import org.space.ai.domain.ProductVo;
import org.space.ai.feign.ProductFeignClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 商品服务降级处理
 */
@Component
public class ProductFeignFallbackFactory implements FallbackFactory<ProductFeignClient> {
    private static final Logger log = LoggerFactory.getLogger(ProductFeignFallbackFactory.class);

    @Override
    public ProductFeignClient create(Throwable throwable) {
        log.error("商品服务调用失败:{}", throwable.getMessage());
        return new ProductFeignClient() {
            @Override
            public TableDataInfo<ProductVo> listProducts(ProductBo bo, Integer pageNum, Integer pageSize) {
                log.error("获取商品列表失败:{}", throwable.getMessage());
                return new TableDataInfo<>();
            }
        };
    }
}
